﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DailyRssDownload.Lib {
    /// <summary>
    /// Holds the settings of the entire project.  Currently persists all data in DailyRssDownloadSettings.settings, 
	/// which is an XML backed store managed by the .Net framework.  The class retrieves settings in the constructor 
	/// and only saves them on a call to the Save() method.
    /// </summary>
	public class Settings {
        private DailyRssDownloadSettings _objSettings;

		public FeedCollection Feeds { get; set; }
		public string DownloadLocation { get; set; }
		public bool OnlyDownloadNewContent { get; set; }

		public Settings() {
            _objSettings = new DailyRssDownloadSettings();
			if (String.IsNullOrEmpty(_objSettings.DownloadLocation))
				this.DownloadLocation = System.IO.Directory.GetCurrentDirectory();
			else
				this.DownloadLocation = _objSettings.DownloadLocation;
			this.Feeds = FeedCollection.ConvertFeedsToFeedCollection(_objSettings.RssFeeds, _objSettings.AtomFeeds);
			this.OnlyDownloadNewContent = _objSettings.OnlyDownloadNewContent;
		}

		public void Save() {
			_objSettings.DownloadLocation = this.DownloadLocation;
			_objSettings.RssFeeds = RssFeedCollection.GetRssFeedsFromFeedCollection(this.Feeds);
			_objSettings.AtomFeeds = AtomFeedCollection.GetAtomFeedsFromFeedCollection(this.Feeds);
			_objSettings.OnlyDownloadNewContent = this.OnlyDownloadNewContent;
			_objSettings.Save();
		}
	}
}
